package com.h2.gwt.util.ui;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.PopupPanel;

public class ActionPopupPanel extends PopupPanel {

   public ActionPopupPanel() {
      //nothing to do
   }
   
   public ActionPopupPanel(boolean autoHide) {
      super(autoHide);
   }
   
   public void moveToBottom() {
      boolean initiallyShowing = isShowing();
      boolean initiallyAnimated = isAnimationEnabled();

      if (!initiallyShowing) {
        setVisible(false);
        setAnimationEnabled(false);
        show();
      }

      int left = (Window.getClientWidth() - getOffsetWidth()) >> 1;
      int top = Window.getClientHeight() - getOffsetHeight();
      setPopupPosition(Math.max(Window.getScrollLeft() + left, 0),
            Math.max(Window.getScrollTop() + top, 0));

      if (!initiallyShowing) {
        setAnimationEnabled(initiallyAnimated);
         /*
          * Run the animation. The popup is already visible, so we can skip the
          * call to setState.
          */
        setVisible(true);
      }
   }
   
}
